使用@ConfigurationProperties注入


https://www.baeldung.com/configuration-properties-in-spring-boot

  1. transfor to 1 Dto

來源:以下這些格式都映射為hostName

mail:
  hostName: server
  hostname: server
  host_name: server
  host-name: server
  HOST_NAME: server
@Configuration
@EnableConfigurationProperties(ConfigProperties.class)
@ConfigurationProperties(prefix = "mail")
public class ConfigProperties {

    private String hostName;
    private int port;
    private String from;

    // standard getters and setters
}
  1. transfor to many Dto
    (其他)透過yml設定檔注入參數至特定資料結構

這不是一個給新手的一個教學過程,也寫的不是很完整
希望大家多多包涵囉~
主要是給自己的一個紀錄,也分享給有需要的夥伴
這是一個心血來潮,產生的文章
若有喜歡或交流的部分都歡迎在下方留言,多多關照。

##attribute ##spring







你可能感興趣的文章

TechBridge 技術週刊編輯第 200 期的感性時間

TechBridge 技術週刊編輯第 200 期的感性時間

Wake On Lan 實作心得

Wake On Lan 實作心得

NeRF: Neural Rendering 的革命性方法(二)

NeRF: Neural Rendering 的革命性方法(二)






留言討論